package com.ideal.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ideal.po.Dept;
import com.ideal.service.DeptService;

@Controller
public class ShowDeptAction {
	@Resource
	private DeptService deptservice;
	@RequestMapping("/show.do")
	public String findall(HttpServletRequest request){
		request.setAttribute("list", deptservice.findall());;
		return "showdept";
	}
	
	@RequestMapping("/adddept.do")
	public String save(Dept dept) {
		deptservice.save(dept);
		return "redirect:show.do";
	}
	
	@RequestMapping("/delete.do")
	public String delete(Dept dept) {
		deptservice.delete(dept);
		return "redirect:show.do";
	}
	
	@RequestMapping("/premerge.do")
	public String premerge(int deptno,HttpServletRequest request) throws Exception {
		Dept dept=deptservice.findById(deptno);
		request.setAttribute("dept", dept);
		/*System.out.println(dept.getDeptno());
		System.out.println(dept.getDname());
		System.out.println(dept.getLoc());
		System.out.println("---------");*/
		return "mergedept";
	}
	
	@RequestMapping("/mergedept.do")
	public String merge(Dept dept) {
		deptservice.merge(dept);
		System.out.println(dept.getDeptno());
		System.out.println(dept.getDname());
		System.out.println(dept.getLoc());
		return "redirect:show.do";
	}
	
}
